package ciyuan.ChangeMinecraft;

import net.minecraft.item.Items;
import net.minecraft.util.Hand;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

/**
 * @author 150149
 */
@Mod.EventBusSubscriber
public class UnbreakStoneUseWood {

    @SubscribeEvent
    public static void onBlockBreak(BlockEvent.BreakEvent event) {
        if ((event.getPlayer().getItemInHand(Hand.MAIN_HAND).getItem().getDescriptionId().equals(Items.WOODEN_PICKAXE.getDescriptionId())) && event.getWorld().getBlockState(event.getPos()).getBlock().getRegistryName().getPath().toLowerCase().contains("stone")) {
            event.setCanceled(true);
        }
    }

    @SubscribeEvent
    public static void onBreak(PlayerEvent.BreakSpeed event) {
        if ((event.getPlayer().getItemInHand(Hand.MAIN_HAND).getItem().getDescriptionId().equals(Items.WOODEN_PICKAXE.getDescriptionId())) && event.getPlayer().getCommandSenderWorld().getBlockState(event.getPos()).getBlock().getRegistryName().getPath().toLowerCase().contains("stone")) {
            event.setNewSpeed(0);
        }
    }

}
